package com.hcms.admin.dto;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.hcms.common.util.TreeNode;
import com.hcms.mybatis.entity.SysMenu;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SysRolePermissionTreeResponse implements Serializable, TreeNode<SysRolePermissionTreeResponse, Long> {

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @ApiModelProperty("父级ID")
    private Long parentId;

    @ApiModelProperty("栏目类型：0->导航链接；1->功能权限")
    private Integer type;

    @ApiModelProperty("菜单标题")
    private String title;

    @ApiModelProperty("链接地址/权限标识")
    private String permission;

    private List<SysRolePermissionTreeResponse> children = new ArrayList<>();

    public SysRolePermissionTreeResponse(SysMenu menu) {
        this.id = menu.getId();
        this.parentId = menu.getParentId();
        this.type = menu.getMenuType();
        this.title = menu.getMetaTitle();
        if (this.type == 1) {
            this.permission = menu.getPath();
        } else {
            this.permission = "";
        }
    }
}
